import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy, $http } = window
// ===================================================================== Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
const BoardList 	= $Lazy.state(()=>import('@views/_public/board-list'))
// ===================================================================== component
const board_type = [{name: '96板', value: '96'}, {name: '48板', value: '48'}, {name: '16板', value: '16'}]

class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '编号',			name: 'board_num' },
			{ label: '操作人',		name: 'operator_id',	type:'select',		loading:true},
			{ label: '时间',			name: 'jz-time',	 	names: ['start_at','end_at'], type:'date-range' },
			{ label: '项目名称',		name: 'kind_name' },
			// { label: '项目名称',		name: 'kind_id', 		type: 'select', 	loading:true },
			{ label: '科室',			name: 'parent_project_id', 	type: 'select', 	loading:true,	idStr:'uuid' },
			{ label: '岗位',			name: 'project_id', 		type: 'select', 	loading:true },
		],
		// 提交表单列表
		formData : [
			{ label: '编号',			name: 'board_num', 		required:true, half:true },
			{ label: '类型',			name: 'board_type', 	required:true, half:true,	type: 'select',	data: board_type },
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
			this.fetch()
		}
	}
	
	fetch = () => $fn.fetch.call(this,'board-log/index')
	
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 操作人
			$fn.setRow( forms, 'operator_id', await f.getCache({ api:'employee' }) )
			// 科室
			$fn.setRow(forms, 'parent_project_id', await f.getCache({ api:'ke_shi' } ) )
			// 岗位
			$fn.setRow(forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			// 项目名称
			// $fn.setRow(forms, 'kind_id', await f.getCache({ api:'project_select' }) )
			this.setState({ forms })
		})
	}
	
	// 表单
	cols = [
		{ title: '板子编号', 	dataIndex: 'board_num', 			width:80 },
		{ title: '板子类型', 	dataIndex: 'board_type_name', 		width:80 },
		{ title: '批次', 		dataIndex: 'batch', 				width:80 },
		{ title: '项目名称', 	dataIndex: 'kind_name', 			width:200 },
		{ title: '岗位', 		dataIndex: 'project_name', 			width:100 },
		{ title: '科室', 		dataIndex: 'parent_project_name', 	width:100 },
		{ title: '操作时间', 	dataIndex: 'operator_at', 			...$fn.table.time },
		{ title: '操作人', 		dataIndex: 'operator_name', 		...$fn.table.name }
	]
	
	render(){
		return (
			<Page title='板子记录'>
				{/* 搜索 */}
				{ SearchForm.call(this) }
				{/* 表格 */}
				<div className='fx wh'>
					<div className='fx h' style={{width: 510}}>
						{ Table.call(this,{isInit:window.isInit, onRow: ({uuid}) => {
							$http.submit(this, 'board-log/item', { param: {board_log_id: uuid} }).then(res => this.codeListRef.setBoardValue(res))
						}}) }
					</div>
					<div className='ex fv pr10 oh'>
						<BoardList onRef={ref=>this.codeListRef=ref} />
					</div>
				</div>
			</Page>
		)
	}
}

export default Index